package VerticalPrototypes;

import java.sql.*;

/**
 * @author Tyler
 */

//Class for setting an item's status for an inventory.
public class SetInventoryItemStatus {
    
    //Instance of this class being used.
    private static SetInventoryItemStatus instance = null;
    
    public SetInventoryItemStatus()
    {
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;

        //Hardcoded database location.
        String url = "snyamathi.dyndns.org:37965";
        String user = "root";
        String password = "baconatmidnight";
        
        //Hardcoded prototype user_id, item_id, and status code.
        int user_id = 1;
        int item_id = 1;
        int status_code = 101;
        
        try {
            //Connect to the databse.
            con = DriverManager.getConnection(url, user, password);
            st = con.createStatement();

            //Update status code of a specific item in a user's inventory.
			//Tyler's test string: UPDATE userinventory SET status= 101 WHERE userID= 1 AND itemID= 1;
            if(rs == (st.executeQuery("UPDATE userinventory SET status= " + status_code + " WHERE userID= " + user_id + " AND itemID= " + item_id)))
            { /*Success; updated status code of item */ }
            else{ /*Not success.*/ }

            //Prints out results.
            if (rs.next()) {
                System.out.println(rs.getString(1));
            }

        } catch (SQLException ex) {
                //Something happens.
        } finally {
            //Close connections safely - May not need to do this? Overkill?
            try {
                if (rs != null) {
                    rs.close();
                }
                if (st != null) {
                    st.close();
                }
                if (con != null) {
                    con.close();
                }

            } catch (SQLException ex) {
                    //Something happens.
            }
        }
    }
    
    //Execute the setting of an Item's status in a user's inventory.
    public static SetInventoryItemStatus user_SetInventoryItemStatus()
    {
        if(instance == null)
            instance = new SetInventoryItemStatus();
        return instance;
    }  
}